exports = this
exports.CPANEL.MachineGrids = exports.CPANEL.MachineGrids || {}

class exports.CPANEL.MachineGrids.DataTable
  @init: ->
    $("#machine_grids_datatable").DataTable
        pageLength: 25
        bProcessing: true
        bServerSide: true
        stateSave: true
        responsive: true
        sAjaxSource: $("#machine_grids_datatable").data('source')
        language: CPANEL.datatableLanguage
        order: [[5, 'desc']]
        columnDefs: [
          { orderable: false, targets: 0 }
          { orderable: false, targets: 1 }
          { orderable: false, targets: 2 }
          { orderable: false, targets: 3 }
          { orderable: false, targets: 4 }
          { orderable: false, targets: 6 }
        ]
  @refresh: ->
    $("#machine_grids_datatable").DataTable().ajax.reload()

  @search: ->
    machine_id    = $("#search-scope #machine_id").val()
    grid_id       = $("#search-scope #grid_id").val()
    product_id    = $("#search-scope #product_id").val()
    status        = $("#search-scope #status").val()
    search_params = "?machine_id=#{machine_id}&grid_id=#{grid_id}&product_id=#{product_id}&status=#{status}"
    request_url = $("#machine_grids_datatable").data('source') + search_params
    $("#machine_grids_datatable").DataTable().ajax.url(request_url).load()

  @search_reset: ->
    $("#search-scope #machine_id").val('')
    $("#search-scope #select_machines_text").html('');
    $("#search-scope #grid_id").val('')
    $("#search-scope #select_grids_text").html('');
    $("#search-scope #product_id").val('')
    $("#search-scope #select_products_text").html('');
    $("#search-scope #status").val('')

